﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DBconnection;
using RulesCore;

namespace simulation
{
    class Cls
    {
        private string Eng_Name;
        List<Guid> ClsObjects = new List<Guid>();
        Dictionary<string, prm> Prms = new Dictionary<string, prm>();
        Dictionary<string, string[]> MyRules = new Dictionary<string, string[]>();
        static int count = 1;

        public Cls(string EngName)
        {
            this.Eng_Name = EngName;
        }

        //For Building the struct!
        public void addPrm(string engName)
        {
            Prms.Add(engName, new prm(engName)); 
        }

        public string getVal(string prm, Guid id)
        {
            return Prms[prm].GETVALUE(id);
        }

        public void SetVal(string prm, Guid id, string nVal)
        {
            Prms[prm].SETVALUE(id, nVal);
        }

        public void addObject(Guid id,string[] PrmsVal)
        {
            ClsObjects.Add(id);
            int index = 0;
            foreach (var pr in Prms)
            {
                pr.Value.ADDOBJ(id, PrmsVal[index]);
                index++;
            }
        }

        public void DeleteObj(Guid id)
        {
            ClsObjects.Remove(id);
            foreach (var gu in ClsObjects)
            {
                Console.WriteLine(gu);
            }
        }

        public void myRules()
        {
            string[] Rules = DB.GetRulesList();

            foreach (string rule in Rules)
            {
                string[] ruleTxt=DB.GettingRule_Text(rule);
                for (int i = 0; i < ruleTxt.Length; i++)
                {
                    if (ruleTxt[i].Contains(this.Eng_Name))
                    {
                        MyRules.Add(rule, ruleTxt);
                        break;
                    }
                }
            }
        }

        public void CheckMyRules()
        {
            
        }

        public List<string> SearchPrms(string str)
        {
            List<string> prms =new List<string>();
            for (int i = 0; i < str.Length; i++)
            {
                if (str[i] == '[')
                {
                    int indx = i;
                    string build = "";
                    while (str[indx]!=']')
                    {
                        build = build + str[indx];
                        indx++;
                    }
                    build = build + "]";

                    prms.Add(build);
                }
            }
            return prms;
        }


    }
}
